<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="../../static/css/style.css"  media="all">
    <script type="text/javascript" src="../../static/js/jquery.min.js" ></script>
    <script src="../../layui/layui.all.js" charset="utf-8"></script>
    <script src="../../static/js/base.js" charset="utf-8"></script>
    <script src="../../static/js/ax.js"></script>
    <script src="../../static/js/jquery.cookie.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="../../static/js/html5.js"></script>
    <script src="../../static/js/respond.js"></script>
    <![endif]-->
</head>
<body class="bg_w">
<div class="layui-fluid">
    <div class="content-wrap">
        <form class="layui-form layui-form-pane" id="from1">
            <input type="hidden" name="id" id="id" />
            <div class="layui-row layui-col-space15">
                <div class="layui-col-sm6">
                    <label class="layui-form-label">用户账号<span class="red">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" name="username" id="username" disabled="disabled" class="layui-input" lay-verify="required" placeholder="用户账号字母+数字，50字符内">
                    </div>
                </div>
                <div class="layui-col-sm6">
                    <label class="layui-form-label">用户姓名<span class="red">*</span></label>
                    <div class="layui-input-block">
                        <input type="text" name="name" id="name"  class="layui-input"  lay-verify="required" placeholder="用户姓名只能输入汉字、字母和数字，100字符内">
                    </div>
                </div>
            </div>

            <div class="layui-row layui-col-space15">
                <div class="layui-col-xs6">
                    <label class="layui-form-label">管理部门<span class="red">*</span></label>
                    <div class="layui-input-block">
                        <input type="hidden" name="depCode"  id="depCode"/>
                        <input type="text" disabled="disabled" name="depName" id="depName" class="layui-input"  lay-verify="required" placeholder="请选择部门">
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <button type="button" onclick="dep()" class="layui-btn layui-btn-primary">部门</button>
                </div>
            </div>
            <div class="layui-row layui-col-space15">
                <div class="layui-col-xs6">
                    <label class="layui-form-label" >管理岗位<span class="red">*</span></label>
                    <div class="layui-input-block">
                        <input type="hidden" name="positionId"  id="positionId"/>
                        <input type="text" disabled="disabled" name="positionName" id="positionName" class="layui-input"   lay-verify="required" placeholder="请选择岗位">
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <button type="button" onclick="position()" class="layui-btn layui-btn-primary">岗位</button>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-input-block">
                    <a id="btnClose" class="layui-btn layui-btn-primary btn-left">关闭</a>
                    <button class="layui-btn add_btn btn-left" lay-submit="" lay-filter="addNews">提交</button>
                </div>
            </div>
        </form>
    </div>
</div>

<script>
    window.onload=function(){
        var  id=decodeURI(getQueryString('id'));
        ax.post({
            type: "post",
            url: schoolWebUrl+"/user/getUserId",
            data: {id:id},
            contentType: "application/x-www-form-urlencoded",
            success: function (data) {
                $("#id").val(data.data.id);
                $("#depCode").val(data.data.depCode);
                $("#depName").val(data.data.depName);
                $("#positionId").val(data.data.positionId);
                $("#positionName").val(data.data.positionName);
                $("#name").val(data.data.name);
                $("#username").val(data.data.username);
            }
        });
    }

    function dep() {
        top.layui.layer.open({
            id:'',
            title : "部门组织",
            type : 2,
            area: ['600px', '400px'],
            btn: ['确定','取消'],
            content : "./school/sys/departmentList.html",
            yes: function (index,layero) {
                var departmentCode = layero.find("iframe")[0].contentWindow.$("#departmentCode").val();
                var departmentName = layero.find("iframe")[0].contentWindow.$("#departmentName").val();
                if(departmentCode==null || departmentCode==""){
                    layer.msg("请选择部门");
                }else{
                    $("#depCode").val(departmentCode);
                    $("#depName").val(departmentName);
                    layer.close(index);
                }
            } ,
            btn2: function (index,layero) {
                layer.close(index);
            }
        });
    }
    $('#btnClose').on("click", function () {
        parent.layer.close(parent.layer.getFrameIndex(window.name));
    });

    function position() {
        var departmentCode=$("#depCode").val();
        if(departmentCode==null || departmentCode==""){
            layer.msg("请先选择部门");
            return false;
        }
        top.layui.layer.open({
            id:'',
            title : "岗位列表",
            type : 2,
            area: ['850px', '350px'],
            btn: ['确定','取消'],
            content : "./school/positionList.html?departmentCode="+$("#depCode").val(),
            yes: function (index,layero) {
                var positionId = layero.find("iframe")[0].contentWindow.$("#positionId").val();
                var positionName = layero.find("iframe")[0].contentWindow.$("#positionName").val();
                if(positionId==null || positionId==""){
                    layer.msg("请选择岗位");
                }else{
                    $("#positionId").val(positionId);
                    $("#positionName").val(positionName);
                    layer.close(index);
                }
            } ,
            btn2: function (index,layero) {
                layer.close(index);
            }
        });
    }
    layui.config({
        base: "js/"
    }).use(['form', 'layer', 'jquery', 'layedit', 'laydate', 'upload'], function (){
        var form = layui.form;
        var layer = parent.layer === undefined ? layui.layer : parent.layer;
        var laypage = layui.laypage;
        var layedit = layui.layedit;
        var laydate = layui.laydate;
        var $ = layui.jquery;

        //添加验证规则
        form.verify({
            /* code: function (value, item) {
                 if (value != "123456") {
                     return "密码错误，请重新输入！";
                 }
             }*/
        })

        form.on("submit(addNews)", function (data) {
            ax.post({
                type: "post",
                url: schoolWebUrl+"/user/updateUser",
                data: $("#from1").serialize(),
                contentType: "application/x-www-form-urlencoded",
                success: function (data) {
                    layer.msg(data.message);
                    setTimeout(function () {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                    },400)
                }
            });
            return false;
        });
    })
</script>
</body>
</html>